package com.dabbo.starship.cell;
import java.rmi.RemoteException;

import com.dabbo.starship.interfaces.Block;
import com.dabbo.starship.interfaces.Cell;

public class CellPower extends CellDefault {

	private static final long serialVersionUID = 8098341638002693260L;

	protected static int MAX_POWER = 375;
	
	public CellPower(Block parent) throws RemoteException {
		super(parent);
		this.cellType = Cell.CELL_POWER;
		this.cargoAllowed = false;
		this.passable = true;
		this.powerOutput = 0;
	}
	
	@Override
	public void activate() {
		System.out.println("Huh?!");
		this.activated = true;
	}

	@Override
	public void deActivate() {
		this.activated = false;
	}
	
	@Override
	public void tick() {
		if (this.activated) {
			int newValue = this.powerOutput + 1 + (new Double((Math.random() * 5)).intValue());
			if (newValue > CellPower.MAX_POWER) {
				newValue = CellPower.MAX_POWER;
			}
			this.powerOutput = newValue;
		} else {
			int newValue = this.powerOutput - (5 + (new Double((Math.random() * 25)).intValue()));
			if (newValue < 0) {
				newValue = 0;
			}
			this.powerOutput = newValue;
		}
	}

	@Override
	public void powerFailue() {
		int newValue = this.powerOutput - (22 + (new Double((Math.random() * CellPower.MAX_POWER)).intValue()));
		if (newValue < 0) {
			newValue = 0;
		}
		this.powerOutput = newValue;
	}

}
